<style>
    .p-pic {
        width:40px;
        height:40px;
        border: 1px solid #dddddd;
        overflow: hidden;
        margin: 0 auto;
        text-align: center;
    }
    .p-pic img {
        display: block;
        width: 100%;
        max-width: 200px;
        max-height: 200px;
    }
    .tableform tr td{
        position:relative;
    }
    .tableform tr .p-pic.letbig{
        position:absolute;
        z-index: 9999;
        border:1px solid #7a7a7d;
    }
</style>





<div style="position:absolute;width:100%;background:#fff;text-align: center;color: red;font-size: 20px;display: none" id="loading">loading…………</div>
<{if $state=='1'}>
<div style="text-align:right;" id="pager">page
    <input type="text" name="page" value="" >
    <a data-href="index.php?app=b2c&ctl=admin_business_orderlist&act=to_split&business_id=<{$business_id}>&state=<{$state}>&page=">go</a>
</div>
<{/if}>
<form class="tableform" method='post' action='index.php?app=b2c&ctl=admin_order&act=do_confirm' id="order-split-form">
    <input type="hidden" name="business_id" value="<{$business_id}>">
    <table cellpadding="0" cellspacing="0"  class="gridlist">
        <col style="width:5%"></col>
        <col style="width:10%"></col>
        <col style="width:10%"></col>
        <col style="width:10%"></col>
        <col style="width:15%"></col>
        <col style="width:5%"></col>
        <col style="width:5%"></col>
        <col style="width:10%"></col>
        <col style="width:10%"></col>
        <col style="width:10%"></col>
        <col style="width:10%"></col>
        <col style="width:10%"></col>
        <thead>
        <tr>
            <th><{t}>id<{/t}></th>
            <th><{t}>订单号<{/t}></th>
            <th><{t}>下单时间<{/t}>
                <a href="index.php?app=b2c&ctl=admin_business_orderlist&act=to_split&business_id=<{$business_id}>&state=<{$state}>&order=timeup">up</a>
                <a href="index.php?app=b2c&ctl=admin_business_orderlist&act=to_split&business_id=<{$business_id}>&state=<{$state}>&order=timedown">down</a>
            </th>
            <th><{t}>图片<{/t}></th>
            <th><{t}>货品编号<{/t}>
                <a href="index.php?app=b2c&ctl=admin_business_orderlist&act=to_split&business_id=<{$business_id}>&state=<{$state}>&order=bnup">up</a>
                <a href="index.php?app=b2c&ctl=admin_business_orderlist&act=to_split&business_id=<{$business_id}>&state=<{$state}>&order=bndown">down</a>
            </th>
            <th><{t}>品牌<{/t}></th>
            <th><{t}>数量（包装）<{/t}></th>
            <th><{t}>每包装数量<{/t}></th>
            <th><{t}>采购价<{/t}></th>
            <th><{t}>确认数量<{/t}></th>
            <th><{t}>下架<{/t}></th>
            <th></th>
            <th><input class="checkall" type="checkbox" name="checkall"   value="" ></th>
        </tr>
        </thead>
        <tbody>
        <{foreach from=$info item=item}>
        <tr>
            <td><{$item.obj_id}></td>
            <td><{$item.mainOrder_id}></td>
            <td><{$item.createtime|cdate}></td>
            <td>
                <div class="p-pic">
                    <a target="_blank" href="<{$item.image_default_id|default:$env.conf.site.default_thumbnail_pic|storager:'s'}>">
                        <img src="<{$item.image_default_id|default:$env.conf.site.default_thumbnail_pic|storager:'s'}>">
                    </a>


                </div>

                </atarget>
            </td>
            <td><{$item.bn}></td>
            <td><{$item.brand_name}></td>
            <td><{$item.quantity}></td>
            <td><{$item.unit_num}></td>
            <td><{$item.s_cost|cur}></td>
            <td>
                <{if $item.state=='0'}>
                <{input type="text" vtype="required&&number" name="confirm_num[{$item.obj_id}]" class="toShare" value=$item.quantity  q_data=$item.quantity width="10" onblur="check(this)"}>
                <{else $item.state=='1'}>
                <{$item.has_confirm_num}>
                <{/if}>
            </td>
            <td>
                <{if $item.state=='0'}>
                <input class="check_box_mk" type="checkbox" name="marketable[<{$item.obj_id}>]"  data_val="<{$item.obj_id}>" value="">
                <{/if}>
            </td>
            <td>
                <{if $item.state=='0'}>
                <a class="single_confirm" onclick="do_bo_edit('<{link app=b2c ctl=admin_order act=do_bo_edit obj_id=$item.obj_id business_id=$business_id}>',<{$item.obj_id}>)" ><{t}>确认<{/t}></a>
                <{else $item.state=='1'}>
                <{assign var="nums" value=$item.quantity-$item.has_confirm_num}>
                相差 <{$nums}>
                <{/if}>
            </td>
            <td>
                <{if $item.state=='0'}>
                <input class="check_box" type="checkbox" name="has_confirm[<{$item.obj_id}>]"  data_val="<{$item.obj_id}>" value="">
                <{/if}>
            </td>
        </tr>
        <{/foreach}>
        <{if !count($info) > 0}>
        <tr><td colspan=10><{t}>暂无确认库存数据<{/t}></td></tr>
        <{/if}>
        </tbody>
    </table>
    <{if count($info) > 0}>
    <div class="table-action">
        <{if $state=='0'}>
        <{button label=$___b2c="确定"|t:'b2c'  type="button" onclick="dopost()"}>
        <{button label=$___b2c="确定"|t:'b2c' id="order-split-form-submit" class="order-action" type="submit" style="display:none"}>
        <{/if}>
    </div>
    <{/if}>
    </div>
</form>

<script type="text/javascript">
    (function(){
        var _form = $('order-split-form');
        //var btn =$('order-split-form-submit');
        _form.store('target',{
            onRequest:function() {
            },
            onComplete:function(){

            },
            onSuccess:function(response){
                var hash_res_obj = JSON.decode(response);
                if (hash_res_obj.success != undefined && hash_res_obj.success != ""){
//                window.close();
                    window.location.reload();
                }else{}
            }
        });
    })();

    jQuery(function(){
        jQuery('#pager').click(function(){
            if(jQuery(this).find('input').val()!=''){
                var urls = jQuery(this).find('a').attr('data-href') + jQuery(this).find('input').val();
                //window.location.href = urls;
                jQuery(this).find('a').attr('href',urls);
            }
        }) ;
    });
    jQuery('.check_box').prop("checked",true);
    jQuery('.checkall').prop("checked",true);
    jQuery('.checkall').click(function(){
        if(jQuery(this).prop("checked")){
            jQuery('input[name^=has_confirm]').each(
                    function(){
                        jQuery(this).prop("checked",true);
                    }
            );
        }else{
            jQuery('input[name^=has_confirm]').each(
                    function(){
                        jQuery(this).prop("checked",false);
                    }
            );
        }
    });

    jQuery('.check_box').click(function(){
        var keynum =0;
        jQuery('.check_box').each(function(){
            if(jQuery(this).prop('checked')==false){
                keynum++;
            }
            if(keynum>0){
                jQuery('.checkall').prop("checked",false);
            }else{
                jQuery('.checkall').prop("checked",true);
            }

        });
    });
    jQuery('.check_box_mk').click(function(){
            if(jQuery(this).prop('checked')==false){
                  jQuery(this).val(0);
            }else{
                    jQuery(this).val(1);
            }
    });

    function do_bo_edit(urls,obj_id){
        var nums = jQuery("input[name='confirm_num["+ obj_id +"]']").val();
        var marketable = jQuery("input[name='marketable["+ obj_id +"]']").val();
        if(marketable>0){
            var urls = urls + '&marketable=' + 1;
        }else{
            var urls = urls + '&marketable=' + 0;
        }
        var urls = urls + '&con_num=' + nums;
        jQuery.ajax({
            type: 'get',
            url: urls,
            data: '' ,
            dataType: 'JSON',
            beforeSend:function(){
                jQuery("#loading").css('display','block');
            },
            success: function(json) {
                jQuery("input[name='confirm_num["+ obj_id +"]']").parents('tr').remove();
                jQuery("#loading").css('display','none');
            }
        });
    }

    function dopost(){
        var checked = 0;
        jQuery('input[name^=has_confirm]').each(
                function(){
                    if(jQuery(this).prop("checked")){
                        jQuery(this).val(jQuery(this).attr('data_val'));
                        checked+= 1;
                    }
                }
        );
        if( checked > 0 ) {
            jQuery('#order-split-form-submit').trigger(jQuery.Event("click"));
            /* jQuery('#MODALPANEL').css('display','none');
             jQuery('.dialog').remove();*/
            // location.reload();

        }else{
            alert('请选择需要确认的商品');
        }
    }

    function check(obj){
        var gc_confirm_num = obj.get('value');
        var quantity = obj.get('q_data');
        if(isNaN(gc_confirm_num)){
            obj.set('value',quantity);
        }
        if(gc_confirm_num<0){
            obj.set('value',quantity);
        }
        if(gc_confirm_num>quantity){
            obj.set('value',quantity);
        }
    }

    /*var confirm = $('order-split-form');
     confirm.addEvents({
     'click:relay(.single_confirm)':function(e){
     e.preventDefault();
     var self = this;
     var input = this.getParent('td').getPrevious('td').getElement('.toShare');
     var num = input.get('value');
     self.href += '&con_num=' + num;
     new Request({
     url:self.href,
     method:'post',
     onSuccess:function(re){
     try{
     var _dialogIns = self.getParent('.dialog').retrieve('instance');
     }catch(e){}

     if(_dialogIns)
     {
     //_dialogIns.close();
     }
     }
     }).send();
     }
     });*/


    //  ===============================列表页面图片变大效果=======================================================
    jQuery(".tableform tr td .p-pic").hover(function(){
        var owntop=jQuery(window).height()-(jQuery(this).offset().top - jQuery(document).scrollTop()+50);
        var new_img= jQuery(this).clone();
        jQuery(this).parent().append(new_img);
        if(owntop>160){
            jQuery(this).siblings('.p-pic').addClass('letbig').stop().animate({width:160, height:160,top:44,left:70},0);
        }else{
            jQuery(this).siblings('.p-pic').addClass('letbig').stop().animate({width:160, height:160,top:-156,left:70},0);
        }
    },function(){
        jQuery(this).siblings('.p-pic').remove();
    });
</script>